using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using XVUEfxSDK.Remoting;
using XVUEfxSDK.Xsequencer;

namespace ApplicationUseRemoting
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            buttonDisconnect.Enabled = false;
            groupBoxProperties.Enabled = true;
            buttonConnect.Enabled = true;
            mainUserControlSamples1.Enabled = false;
        }

        XvueFxSequencerClient client = new XvueFxSequencerClient();

        private void buttonConnect_Click(object sender, EventArgs e)
        {
            try
            {
                //connect to the remoting iOrasis at specified properties
                if (client.ActivateClient
                    (false, 
                    textBoxRemotingIP.Text , 
                    textBoxRemotePort.Text , 
                    textBoxRemoteName.Text , 
                    "9201"))
                {
                    buttonConnect.Enabled = false;
                    buttonDisconnect.Enabled = true;
                    groupBoxProperties.Enabled = false;
                    mainUserControlSamples1.Enabled = true;

                    //We push the IXvueSequencerUser interface that we got from remoting 
                    //to the samples
                    mainUserControlSamples1.SetSequencer(client.xSequencer);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void buttonDisconnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (client.CloseClient())
                {
                    buttonConnect.Enabled = true;
                    buttonDisconnect.Enabled = false;
                    groupBoxProperties.Enabled = true;
                    mainUserControlSamples1.Enabled = false;
                    //we push null as IXvueSequencerUser interface to trigger 
                    //any plugins close actions
                    mainUserControlSamples1.SetSequencer(null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (buttonDisconnect.Enabled)
                buttonDisconnect_Click(this, null);

        }

    }
}